package person.bing.fbcloud.controller;


import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import person.bing.fbcloud.common.core.exception.CheckedException;
import person.bing.fbcloud.common.core.util.R;
import person.bing.fbcloud.service.SysOauthClientDetailsService;

//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.context.SecurityContext;
//import org.springframework.security.core.context.SecurityContextHolder;

/**
 * <p>
 * 终端信息表 前端控制器
 * </p>
 *
 * @author mengfb
 * @since 2019-12-20
 */
@RestController
@RequestMapping("/client")
public class SysOauthClientDetailsController {
    @Autowired
    private SysOauthClientDetailsService sysOauthClientDetailsService;

    /**
     * 根据客户端id获取详情
     * @param jsonObject
     * @return
     */
    @PostMapping("/getClientById")
    public R getClientById(@RequestBody JSONObject jsonObject){
        String clientId = jsonObject.getStr("clientId");
        if (StrUtil.isEmpty(clientId)){
            throw new CheckedException("clientId不能为空！！");
        }
        return new R(sysOauthClientDetailsService.getUserByUserName(clientId));
    }

    /**
     * 获取认证上下文
     * @return
     */
    /*@GetMapping("/getSecurityContext")
    public R getSecurityContext(){
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
        Object credentials = authentication.getCredentials();
        Object details = authentication.getDetails();
        Object principal = authentication.getPrincipal();
        boolean authenticated = authentication.isAuthenticated();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("authorities",authorities);
        jsonObject.put("credentials",credentials);
        jsonObject.put("details",details);
        jsonObject.put("principal",principal);
        jsonObject.put("authenticated",authenticated);
        return new R(jsonObject);
    }*/
}
